package com.lamd.myzhxy.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lamd.myzhxy.pojo.Clazz;
import com.lamd.myzhxy.service.ClazzService;
import com.lamd.myzhxy.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.ResultSet;
import java.util.List;

@RestController
@RequestMapping("/sms/clazzController")
@Api(tags = "班级管理")
public class ClazzController {

    @Autowired
    private ClazzService clazzService;

    @ApiOperation("查询所有的班级的信息")
    @GetMapping("/getClazz")
    public Result getClazzs(){
        List<Clazz> clazzes = clazzService.getClazzs();

        return Result.ok(clazzes);
    }

    @ApiOperation("删除单个或多个班级信息")
    @DeleteMapping("/deleteClazz")
    public Result deleteClazz(@RequestBody List<Integer> ids){
        clazzService.removeByIds(ids);
        return Result.ok();
    }

    @ApiOperation("增加或者修改班级信息")
    @PostMapping("/saveOrUpdateClazz")
    public Result saveOrUpdateClazz(@RequestBody Clazz clazz){
        clazzService.saveOrUpdate(clazz);
        return Result.ok();
    }
    @ApiOperation(value = "模糊查询班级")
    @GetMapping("getClazzByOpr/{pageNo}/{pageSize}")
    public Result getClazzByOpr(Integer pageNo, Integer
            pageSize, Clazz clazz){

        Page<Clazz> page = new Page<>(pageNo,pageSize);
        IPage<Clazz> iPage = clazzService.getClazzsByOpr(page,clazz);
        return Result.ok(iPage);
    }
}
